package com.example.ranrabbitmq.config;

import com.example.ranrabbitmq.pojo.Rabbitmq;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/***
 * NAME:Ran
 * TIME:2024/12/20
 * rabbitmq配置类
 */
@Configuration
public class rabbitmqConfig {

    // 声明交换机
    @Bean
    public DirectExchange myExchange() {
        return new DirectExchange(Rabbitmq.getExchange());
    }

    //    声明队列
    @Bean
    public Queue myQueue() {
        return new Queue(Rabbitmq.getQueue(), true); // 持久化队列
    }

    // 声明绑定 设置路由秘钥
    @Bean
    public Binding binding(Queue myQueue, DirectExchange myExchange) {
        return BindingBuilder.bind(myQueue).to(myExchange).with(Rabbitmq.getKey());

    }


}
